home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / go4gw_1.01 / g2whois < prev    next >
Encoding:
Text File  |  1992-09-17  |  3.1 KB  |  147 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #----------------------------------------------------------------------
  4. # variables you should change:
  5.  
  6. $whois_server = "umn.edu";   
  7. $whois_port   = 43;
  8.  
  9. #----------------------------------------------------------------------
  10.  
  11. sub whois_main {
  12.     local($_) = @_;
  13.     
  14.     if (/^$/) {
  15.     &Greply("0Search Instructions\thelp\t$whois_server\t$whois_port");
  16.     &Greply("7Query Whois server $whois_server\t$Ggw $whois_server\t$Ghost\t$Gport");
  17.     &Greply(".");
  18.     exit(0);
  19.     }
  20.     
  21.     ($whois_server, $query) = split('\t');
  22.     
  23.     &GopenServer($whois_server,$whois_port);
  24.     &Gsend($query);
  25.     
  26.     while(<GSERVER>) {
  27.     s/\n//;
  28.     s/\r//;
  29.         push(@lines,$_);
  30.     }
  31.     
  32.     #
  33.     # Always return the output of the whois search first
  34.     #
  35.     
  36.     &Greply("0Raw search results\t$query\t$whois_server\t$whois_port");
  37.     
  38.     
  39.     #
  40.     # Test for some common formats
  41.     #
  42.     
  43.     #
  44.     # CSO gateway whois type servers
  45.     #
  46.     
  47.     foreach (@lines) {
  48.     if (/\s+name:\s+(.*)/ ||
  49.         /\s+person:\s+(.*)/) {
  50.         $newquery = $1;
  51.         $newquery =~ s/,//g; #remove commas
  52.         $newquery =~ s/\s+[A-z]$//; #remove trailing middle initial
  53.         &Greply("0$1\t$newquery\t$whois_server\t$whois_port");
  54.     }
  55.     }
  56.     
  57.     #    
  58.     # nic.ddn.mil type whois servers
  59.     #
  60.     
  61.     foreach (@lines) {
  62.     if (/(.*)\((.*)\)\t(.*)$/) {
  63.         &Greply("0$1\t!$2\t$whois_server\t$whois_port");
  64.     }
  65.     }
  66.     
  67.     #
  68.     # format used by stanford.edu
  69.     #    
  70.     if ($lines[$#lines] =~ /^\(returned/) {
  71.     foreach (@lines) {
  72.         if (/(.*)<(.*)>.*\s+(.*)$/) {
  73.         $text=$1; $handle=$2; $rest = $3;
  74.         $text =~ s/\s+$//;
  75.         $rest =~ s/\s+/ /g;
  76.         &Greply("0$text ($rest)\t$handle\t$whois_server\t$whois_port");
  77.         }
  78.         }
  79.     }
  80.     
  81.     #
  82.     # format used by X.500 gateways.
  83.     #
  84.     if ($lines[0] =~ m/[0-9]+ matches found/) {
  85.         foreach (@lines) {
  86.         if (/^\s+[0-9]+\.(.*)\s+   (.*)$/) {
  87.                 $newname = $1;
  88.                 $newname =~ s/^\s+//;
  89.         $newname =~ s/\s+$//;
  90.         &Greply("0$newname ($2)\t$newname\t$whois_server\twhois_port");
  91.         }
  92.         }
  93.     }
  94.     
  95.     #
  96.     # Format used by sunysb.edu, software unknown.
  97.     #
  98.     if ($lines[0] =~ /^Connection received/) {
  99.     foreach (@lines) {
  100.         if (/^(.*)MailName:/) {
  101.         &Greply("0$1\t$1\t$whois_server\twhois_port");
  102.         }
  103.         }
  104.     }
  105.     
  106.     #
  107.     # format used by horton: username@host  Name  Date
  108.     #
  109.     
  110.     foreach (@lines) {
  111.         if (/([\S]+@[\S]+).*([A-z][A-z][A-z] [A-z][A-z][A-z]\d\d \d\d\d\d)[\s]+$/) {
  112.         #Not implemented yet.
  113.         }
  114.     }
  115.     
  116.     
  117.     
  118.     foreach (@lines) {
  119.     if (/^\s+name:\s+(.*)/) {
  120.         &Greply("0$1\t$query\t$whois_server\t$whois_port");
  121.         &Greply(".");
  122.         exit(0);
  123.     }
  124.     }
  125.  
  126.     if ($lines[$#lines] eq 'NO MATCH') {
  127.     &Greply("0No Match Was Found!\thelp\t$gopher_server\t$gopher_port");
  128.     } elsif ($lines[$#lines] =~ /^\(returned/) {
  129.     foreach (@lines) {
  130.         if (/(.*)<(.*)>.*\s+(.*)$/) {
  131.         $text=$1; $handle=$2; $rest = $3;
  132.         $text =~ s/\s+$//;
  133.         $rest =~ s/\s+/ /g;
  134.         &Greply("0$text ($rest)\t!$handle\t$whois_server\t$whois_port");
  135.         }
  136.     }
  137.     }
  138.     
  139.     &Greply(".");
  140.     exit(0);
  141. }
  142.  
  143.  
  144.  
  145.  
  146. 1; # for require
  147.